<template>
  <!--未成交-->
  <el-dialog
    :close-on-click-modal="false"
    title="未成交"
    :visible.sync="dialogVisible5"
    :beforeClose="handleClose5"
    width="400px">
    <div>
      <el-form size="mini" :model="sendForm5" label-width="100px"  ref="sendForm5" :rules="rules5">
        <el-form-item label="未成交原因：" prop="unOrderReason">
          <el-select style="width:200px" v-model="sendForm5.unOrderReason">
            <el-option v-for="item in reasonList" :label="item.reasonValue" :value="item.reasonValue" :key="item.reasonId" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注：">
          <el-input type="textarea" style="width:200px" v-model="sendForm5.unOrderRemark"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose5">取 消</el-button>
          <el-button type="primary" @click="handleConfirm5" :loading="btnLoading5">确 认</el-button>
      </span>
  </el-dialog>
</template>
<script>
import {inquiryOperate,unOrderReasonList,batchSetUnOrder} from '@/api/allInLine/inquiry'
import { mapGetters } from 'vuex'
import { Message } from 'element-ui';

const defaultSendForm5={
  unOrderReason:'',
  inquiryId:'',
  reducePrice:'',
  purchasePrice:'',
  unOrderType:'销售',
  unOrderRemark:'',
  operateType:'unOrder'
};

export default {
  name: "index",
  data(){
    return {
      dialogVisible5:false,
      btnLoading5:false,
      sendForm5:JSON.parse(JSON.stringify(defaultSendForm5)),
      rules5:{unOrderReason:[{required:true,message:'请选择未成交原因',trigger:'change'}]},
      reasonList:[],
      type:''
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),
  },
  components : {

  },
  created() {
  },
  filters: {

  },
  methods:{

    getUnOrderReasonList(){
    unOrderReasonList({reasonType:'销售'}).then(res=>{
      this.reasonList = res
    })
    },

    //显示未成交
    showPop5(item,type){
      this.dialogVisible5 = true;
      this.type = type ? type :'one'
      this.getUnOrderReasonList()
      if (Array.isArray(item)) {
        let inquiryIds = item.map(item=>item.inquiryId).join(",")
        this.sendForm5.inquiryId = inquiryIds
      } else {
        this.sendForm5.inquiryId=item.inquiryId
      }
    },
    //关闭未成交
    handleClose5(){
      this.dialogVisible5 = false;
      this.$refs.sendForm5.resetFields()
      this.sendForm5 = JSON.parse(JSON.stringify(defaultSendForm5))
    },

    //确认未成交
    handleConfirm5(){
      this.$refs.sendForm5.validate(valid=>{
        if(valid){
          this.btnLoading5=true
         const data = JSON.parse(JSON.stringify(this.sendForm5))
          let fn = this.type == 'more' ? batchSetUnOrder : inquiryOperate
          fn(data).then(res=>{
         Message.success('提交成功')
         this.btnLoading5=false
         this.$refs.sendForm5.resetFields()
         this.sendForm5 = JSON.parse(JSON.stringify(defaultSendForm5))
         this.$emit('update')
         this.dialogVisible5 = false;
      }).catch(error=>{
        this.btnLoading5=false
      })
        }
      })

    },
  },
}
</script>

<style  lang="scss">

</style>
